//
//  MapScene.cpp
//  beast_tamer
//
//  Created by Yang Bean on 13/5/3.
//
//

#include "MapScene.h"
#include "HelloWorldScene.h"
#include "TamerScene.h"
static const float BUTTON_GAP = 50;
static const float ANIMATION_GAP = 100;

using namespace cocos2d;
CCScene* MapScene::scene()
{
    // 'scene' is an autorelease object
    CCScene *scene = CCScene::create();
    
    // 'layer' is an autorelease object
    MapScene *layer = MapScene::create();
    
    // add layer as a child to scene
    scene->addChild(layer);
    
    // return the scene
    return scene;
}

MapScene::MapScene(void)
{
    
}
MapScene::~MapScene(void)
{
    
}


bool MapScene::init(void)
{
    
    this->setMenu();
    return true;
}
void MapScene::setMenu()
{
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    CCMenuItemSprite* tamerButton = button("b_tamer.png", menu_selector(MapScene::toTamer));
    CCMenuItemSprite* monsterButton = button("b_monster.png", menu_selector(MapScene::toMonster));
    CCMenuItemSprite* pediaButton = button("b_pedia.png", menu_selector(MapScene::toPedia));
    CCMenuItemSprite* storeButton = button("b_store.png", menu_selector(MapScene::toStore));
    CCMenuItemSprite* teamButton = button("b_team.png", menu_selector(MapScene::toTeam));
    CCMenuItemSprite* battleButton = button("b_battle.png", menu_selector(MapScene::toBattle));
    CCArray* buttonArray = CCArray::create(tamerButton, monsterButton, pediaButton,
                                           storeButton, teamButton, battleButton,NULL);
    for (int i = 0; i < buttonArray->count(); i++)
    {
        CCMenuItemSprite* button = dynamic_cast<CCMenuItemSprite*>(buttonArray->objectAtIndex(i));
        button->setAnchorPoint(ccp(0,1));
        button->setPosition(- winSize.width / 2 - ANIMATION_GAP,
                            - winSize.height / 2 + BUTTON_GAP * (buttonArray->count() - i));
        CCMoveTo* move = CCMoveTo::create(0.2 * i, ccp(- winSize.width / 2, button->getPositionY()));
        button->runAction(move);
    }
    CCMenu* menu = CCMenu::createWithArray(buttonArray);
    this->addChild(menu);
    
    
    
}

CCMenuItemSprite* MapScene::button(const char* imgName, SEL_MenuHandler selector)
{
    CCSprite* normalSprite = CCSprite::create(imgName);
    CCSprite* selectSprite = CCSprite::create(imgName);
    selectSprite->setScaleX(1.5);
    CCMenuItemSprite* button = CCMenuItemSprite::create(normalSprite, selectSprite, this,
                                                        selector);
    return button;
}


void MapScene::toTamer()
{
    CCDirector* director = CCDirector::sharedDirector();
    director->replaceScene(TamerScene::scene());
}
void MapScene::toMonster()
{
    CCDirector* director = CCDirector::sharedDirector();
    director->replaceScene(HelloWorld::scene());
}
void MapScene::toPedia()
{
    
}
void MapScene::toTeam()
{
    
}
void MapScene::toStore()
{
    
}
void MapScene::toBattle()
{
    CCDirector* director = CCDirector::sharedDirector();
    director->replaceScene(HelloWorld::scene());
}
